/**
*	插件：流程模块详情页
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.fcheck = {

	create:function(cans){
		var me = this;
		this.rand 	  = cans.rand;
		this.formname = 'checkform'+this.rand+'';
		
		this.getcourse = function(){
			var s = '<form name="'+this.formname+'" autocomplete="off"><table width="100%">',da = this.flowcourse,d,sty='',mda=false,acts,i,acta,das = this.flowcourselog,s1 = '';
			
			if(das)for(i=0;i<das.length;i++){
				d = das[i];
				if(i>0)s1+=' → ';
				s1+=''+d.name+'('+d.checkname+'<font color="'+d.statuscolor+'">'+d.statusname+'</font>)';
			}
			for(i=0;i<da.length;i++){
				d = da[i];
				if(d.ischeck==1)continue;//已审批就不显示了
				sty = '';
				if(d.isnow==1){
					sty='font-weight:bold;color:blue';
				}else if(d.ischeck==0){
					sty='color:#888888';
				}
				s1+= '<span style="'+sty+'">';
				if(i>0 || das.length>0)s1+=' → ';
				s1+=''+d.name+'('+d.checkname+')';
				s1+='</span>';
				if(d.ismycheck==1)mda = d;
			}
			
			s+='<tr><td style="text-align:right; min-width:90px" nowrap class="hui fontsize14">流程状态：</td><td style="padding:8px 5px;width:95%">'+this.nowstatus()+'</td></tr>';
			
			s+='<tr><td style="text-align:right; min-width:90px" nowrap class="hui fontsize14">处理流程：</td><td style="padding:8px 5px;width:95%">'+s1+'</td></tr>';

			if(mda){
				acts = mda.courseact;if(!acts)acts='同意,不同意';
				acta = acts.split(',');
				this.courseactarr = acta;
				s+='<tr><td style="text-align:right" class="hui fontsize14">审批动作：</td><td style="padding:8px 5px">';
				for(i=0;i<acta.length;i++){
					s+='<label><input clickevt="clickaction" type="radio" name="courseact" value="'+(i+1)+'">'+acta[i]+'</label> &nbsp; ';
				}
				s+='</td></tr>';
				
				s+='<tr style="display:none" id="tuihuidiv_'+this.rand+'"><td style="text-align:right" class="hui fontsize14">退回：</td><td style="padding:8px 5px">不同意退回给提交人</td></tr>';
					
				s+='<tr><td style="text-align:right" class="hui fontsize14">说明：</td><td style="padding:8px 5px">';
				s+='<textarea class="textarea" name="explain" style="flex:1;height:60px" placeholder="不同意就要输入说明"></textarea>';
				s+='</td></tr>';
				
				s+='<tr><td></td><td style="padding:8px 5px">';
				s+='<button class="webbtn" type="button" clickevt="submitcheck">提交审批</button>';
				s+='&nbsp;<span id="msgview_'+this.rand+'"></span>';
				s+='</td></tr>';
			}
			
			s+='</table></form>';
			return s;
		}
		
		this.nowstatus = function(){
			var d = this.flowstatus;
			var str = d.statusname;
			if(d.status==0){
				str = str.replace('?', '<font color="'+d.statuscolor+'">'+d.checkname+'</font>');
				str = ''+d.coursename+'('+str+')';
			}else{
				str = '<font color="'+d.statuscolor+'">'+str+'</font>';
			}
			return str;
		}
		
		this.submitcheck=function(o1){
			var da = js.getformdata(this.formname);
			var zt = da.courseact;
			var msg= 'msgview_'+this.rand+'';
			if(!zt){
				js.setmsg('请选择审批动作','',msg);
				return;
			}
			if(zt==2 && !da.explain){
				js.setmsg('动作是'+this.courseactarr[zt-1]+'，必须输入说明','',msg);
				return;
			}
			if(da.explain)da.explain = jm.base64encode(da.explain);
			js.setmsg('处理中...' ,'',msg);
			js.ajax.post({
				url: 'api/flow/check?num='+this.num+'&mid='+this.mid+'',
				data:da,
				cnum:this.cnum,
				funitid:this.funitid,
				btnobj:o1,
				onsuccess:function(ret){
					js.setmsg('','',msg);
					me.checksuccess();
				},
				onerror:function(ret){
					js.setmsg(ret.msg,'',msg);
				}
			});
		}
		
		//点击动作的
		this.clickaction = function(o1){
			setTimeout(function(){o1.checked = true;},10);
			var val = o1.value;
			var obj = $('#tuihuidiv_'+this.rand+'');
			if(val=='2'){
				obj.show();
			}else{
				obj.hide();
			}
		}
		
		this.checksuccess = function(){
			js.show.success('处理完成');
			this.formdisabled();
			this.xiangobj.closetan();
		}
		
		this.formdisabled=function(){
			$(document[this.formname]).find('*').attr('disabled', true);
		}
		
	}
}